<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <jsp:include page="/WEB-INF/jsp/head.jsp">
        <jsp:param value="游戏经营管理" name="pageTitle"/>
    </jsp:include>
    <script src="/js/common.js"></script>
</head>
<body>
<div class="easyui-panel" data-options="fit:true" style="width:100%;height:100%;padding:10px;">
    <table id="GamesTb" style="width:100%;height:100%"></table>
    <div id="tb" style="padding:5px;height:auto">
        <a href="javascript:;" id="lbtnAdd" title="新增游戏经营" class="easyui-linkbutton"><i class="fa fa-plus"></i>&nbsp;新增</a>
        <a href="javascript:;" id="lbtnAlter" title="修改游戏经营" class="easyui-linkbutton"><i class="fa fa-plus"></i>&nbsp;修改</a>
        <a href="javascript:;" id="lbtnDel" class="easyui-linkbutton"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
    </div>
</div>




<script>

    $('#lbtnAdd').click(function(e){
        e.preventDefault();
        e.stopPropagation();
        window.location.href='/games/newGame';
    });


    //修改游戏信息
    $('#lbtnAlter').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        var rows = $('#GamesTb').datagrid('getSelections');

        if (rows.length == 0 || rows.length>1) {
            $.messager.show({
                title: '修改游戏信息',
                msg: "必须选择一项进行修改",
                timeout: 5000,
                showType: 'slide'
            });
        }

        if (rows.length == 1){
            var row = JSON.stringify($('#GamesTb').datagrid('getSelected'));
                var row = $('#GamesTb').datagrid('getSelected');
                var gid = row.gid;
                var url = "/games/alterGame?gid=" + gid;
                self.location.href = url;
            }
    });


    //批量删除
    $("#lbtnDel").click(function () {
        var rows = $('#jijinyusuanTb').datagrid('getSelections');
        if (rows.length == 0) {
            $.messager.show({
                title: '删除基金预算',
                msg: "未选中记录",
                timeout: 5000,
                showType: 'slide'
            });
        }

        if (rows.length >= 1) {
            $.messager.confirm("删除警告", "您确定要删除共" + rows.length + "记录吗？", function (data) {
                if (data) {
                    var ids = [];
                    for (var i = 0; i < rows.length; i++) {
                        ids.push(rows[i].gid);
                    }
                    $.ajax({
                        type: "POST",
                        url: "/games/deleteAll",
                        data: {
                            "deleteIdString": ids.toString()
                        },
                        dataType: "json",
                        success: function (data) {
                            $.messager.alert('提示信息', data['msg'], 'info', function () {
                                //跳转地址
                                location.href = "/games/home";
                            });
                            $('.panel-tool-close').hide();//隐藏关闭按钮
                        }
                    })
                }
                else {

                }
            });
        }
    });



    //rows,page
    $('#GamesTb').datagrid({
        iconCls: 'icon-search',
        title: '游戏经营管理',
        url: '/games/getAll',
        method: 'get',
        singleSelect: "false",
        checkOnSelect: 'false',
        rownumbers: true,
        pagination: true,
        pageSize: 20,
        toolbar: '#tb',
        columns: [[
            {field: 'ck', checkbox: true}
            , {field: 'gid', align: 'center', width: '100', title: '游戏ID', hidden: 'true'}
            , {field: 'gname', width: '200',align: 'left', title: '游戏名字'}
            , {field: 'buyProportion', width: '200',align: 'left', title: '买分的比例'}
            , {field: 'sellProportion', width: '200',align: 'left', title: '卖分的比例'}
            , {field: 'stockProportion', width: '200',align: 'left', title: '进货的比例'}
            , {field: 'isuse', align: 'center', width: '100', title: '是否启用',formatter:formatState}

        ]],
        onLoadSuccess: function (data) {
            if (data.total == 0) {
                $.messager.alert('提示信息', '没有相关记录！', 'warning');
            }
        }

    });
</script>
</body>
</html>
